package com.itheima.config;


import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;


public class JdbcConfig {
    @Value("${jdbc.driverClassName}")
    private String driverClassName;

    @Value("${jdbc.url}")
    private String url;

    @Value("${jdbc.username}")
    private String username;

    @Value("${jdbc.password}")
    private String password;

     @Bean
     //将返回的DataSource对象添加到Spring容器中
     public DataSource druidDataSource(){
         //1. 创建一个DruidDataSource对象
         DruidDataSource druidDataSource = new DruidDataSource();
         //配置数据库连接
         druidDataSource.setDriverClassName(driverClassName);
         druidDataSource.setUrl(url);
         druidDataSource.setUsername(username);
         druidDataSource.setPassword(password);
         return druidDataSource;
     }
}
